#coding: utf-8

from django.db import models
from django.contrib.auth.models import User
from django.core.files.storage import FileSystemStorage

from django import forms

from upload.models import UploadModel

class Condominos(models.Model):
    proprietario = models.CharField(max_length=50, blank=True, verbose_name="Owner Name")
    email = models.CharField(max_length=50,blank=True)
    user = models.OneToOneField('auth.User', verbose_name="User")
    morada = models.TextField( verbose_name="Address",blank=True)
    nif  = models.CharField(max_length=50, blank=True, verbose_name="TIN - Taxpayer Identification Number")
    telefone = models.CharField(max_length=50, blank=True, verbose_name="Telephone")

    def __unicode__(self):
        return self.proprietario

    class Meta:
        ordering = ["proprietario"]
    

class ProfileForm(forms.ModelForm):
    """
    Profile Form. Composed by all the Profile model fields.							
    """
    class Meta:
        model = Condominos
        exclude = 'user'
        

FRACTION_CHOICES = (
    ('A','A'),
    ('B','B'),
    ('C','C'),
    ('D','D'),
    ('E','E'),
    ('F','F'),
    ('G','G'),
    ('H','H'),
)

FRACTION_TYPE_CHOICES = (
    ('T2','T2'),
    ('T3','T3'),
)
class Fraccoes(models.Model):
    fraccao = models.CharField(max_length=1, choices=FRACTION_CHOICES,  verbose_name="Fraction")
    proprietario = models.ForeignKey(Condominos,  verbose_name="Owner Name")
    #dono = models.ForeignKey(Condominos,  verbose_name="Dono")
    fraccaoTipo = models.CharField(max_length=2, choices=FRACTION_TYPE_CHOICES,  verbose_name="Tipology")
    obs = models.TextField( verbose_name="Details", blank=True)
    
    def __unicode__(self):
        return self.fraccao

    class Meta:
        ordering = ["fraccao"]


class Fornecedores(models.Model):
    nomeFornecedor = models.CharField(max_length = 100,  verbose_name="Supplier Name")
    descricao = models.TextField( verbose_name="Short description of supplier", blank=True)
    nif  = models.CharField(max_length = 100,  verbose_name="TIN - Taxpayer Identification Number",blank=True)
    morada = models.TextField(verbose_name="Address", blank=True)
    telefone = models.CharField(verbose_name="Telephone", max_length = 100,blank=True)
    email = models.CharField(max_length = 100,blank=True)
    
    def __unicode__(self):
        return self.nomeFornecedor

    class Meta:
        ordering = ["nomeFornecedor"]
    
   
class Despesas(models.Model):
    nrFactura = models.CharField(max_length = 10,  verbose_name="Number - receipt of expenditure")
    despesa = models.TextField(verbose_name="Expense")
    nomeFornecedor = models.ForeignKey(Fornecedores,  verbose_name="Supplier")
    custo = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="Expense value", help_text="Enter the value in €")
    data = models.CharField(max_length = 100, help_text="Enter the date of expens <em>(DD-MM-AAA)</em>")
    obs  = models.TextField(verbose_name="Details", blank=True)
    recibo = models.ForeignKey(UploadModel, verbose_name="Receipt File", limit_choices_to={'category': '1'},blank=True, null=True)


    def __unicode__(self):
        return self.nrFactura

    class Meta:
        ordering = ["nrFactura"]   
     	



class Receitas(models.Model):
    PROFITS_CHOICES = (
    	 ('1','First quarter'),
    	 ('2','Second quarter'),
    	 ('3','Third quarter'),
    	 ('4','Fourth quarter'),
    	 ('5','Other'),
    )
    PAYMENT_CHOICES = (
    	 ('1','Cash'),
    	 ('2','Bank Transfer'),
    	 ('3','Other'),
    )
    CHOICES = ((False, 'Unpaid'),(True, 'Paid'))
    
    nrFactura = models.CharField(verbose_name="Number - receipt of income", max_length = 10)
    receita = models.CharField(max_length = 100, verbose_name="Income type", choices=PROFITS_CHOICES)
    #pagador = models.ForeignKey(Condominos, verbose_name="Pagamento", help_text="Seleccione o proprietario correspondente à receita")
    fraccao = models.ForeignKey(Fraccoes, verbose_name="Fraction")
    valor = models.DecimalField(max_digits=7, decimal_places=3, verbose_name="Income value", help_text="Enter the income in €")
    situacao = models.BooleanField(verbose_name="State of payment", choices=((False, 'Unpaid'), (True, 'Paid')))
    modoPagamento = models.CharField(max_length = 100, verbose_name="Payment method", choices=PAYMENT_CHOICES, blank=True)
    dataEmissao = models.CharField(max_length = 100,verbose_name="date of issue",help_text="Enter the date of issue <em>(DD-MM-AAA)</em>",blank=True)
    dataPagamento = models.CharField(max_length = 100,verbose_name="Data of payment",help_text="Enter the date of payment <em>(DD-MM-AAA)</em>",blank=True)
    obs  = models.TextField(verbose_name="Details", blank=True)






        
